package com.wxg.common.core.utils;

import java.util.Random;

/**
 * Created by void on 2019/6/30.
 */
public class RandomCharUtil {

    /**
     * 小写字母
     */
    private static String lowerLetter = "abcdefghijkmlnopqrstuvwxyz";

    /**
     * 大写字母
     */
    private static String upperLetter = "ABCDEFGHIJKMLNOPQRSTUVWXYZ";

    /**
     * 大小写混合
     */
    private static String mixLetter = "abcdefghijkmlnopqrstuvwxyzABCDEFGHIJKMLNOPQRSTUVWXYZ";

    /**
     * 字母和数字混合字符
     */
    private static String mixChar = "abcdefghijkmlnopqrstuvwxyzABCDEFGHIJKMLNOPQRSTUVWXYZ0123456789";
    /**
     * 获取指定长度的随机小写字母
     * @param length
     * @return
     */
    public static String getLowerLetter(int length){
        StringBuilder sb = new StringBuilder();
        Random random = new Random();
        for(int i=0;i<length;i++){
            int index = random.nextInt(26);
            sb.append(lowerLetter.charAt(index));
        }
        return sb.toString();
    }

    /**
     * 获取指定长度的随机大写字母
     * @param length
     * @return
     */
    public static String getUpperLetter(int length){
        StringBuilder sb = new StringBuilder();
        Random random = new Random();
        for(int i=0;i<length;i++){
            int index = random.nextInt(26);
            sb.append(upperLetter.charAt(index));
        }
        return sb.toString();
    }

    /**
     * 获取混合字符
     * @param length
     * @return
     */
    public static String getMixChar(int length){
        StringBuilder sb = new StringBuilder();
        Random random = new Random();
        for(int i=0;i<length;i++){
            int index = random.nextInt(62);
            sb.append(mixChar.charAt(index));
        }
        return sb.toString();
    }


    /*public static void main(String[] args) {
        System.out.println(getMixChar(6));
    }*/
}
